package com.d3works.apps.sale.db.repo;

import com.d3works.apps.sale.db.AdvancePayment;
import com.d3works.apps.sale.db.SaleOrder;
import com.d3works.apps.sale.service.saleorder.SaleOrderComputeService;
import com.d3works.inject.Beans;
import javax.persistence.PersistenceException;

public class AdvancePaymentSaleRepository extends AdvancePaymentRepository {

  @Override
  public AdvancePayment save(AdvancePayment advancePayment) {
    try {
      SaleOrder saleOrder = advancePayment.getSaleOrder();
      Beans.get(SaleOrderComputeService.class)._computeSaleOrder(saleOrder);
      return super.save(advancePayment);
    } catch (Exception e) {
      throw new PersistenceException(e.getMessage(), e);
    }
  }
}
